﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsInStockTypeDAL.cs
/// 作  者：SAM
/// 时  间：2006.11.10
/// 说  明：ClsInStockTypeDAL类用于入库类别信息相关处理
/// </summary>
public class ClsInStockTypeDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有的入库类别币别信息
    /// </summary>
    /// <returns>返回入库类别信息数据集</returns>
    public DataSet GetInStockTypes()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetInStockDataSet", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 搜索入库类别信息
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <returns>返回搜索信息数据集</returns>
    public DataSet SearchInStockTypes(string Key)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchInStockTypes", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 作废入库类别信息
    /// </summary>
    /// <param>入库类别编号</param>
    /// <param name="Is_Visible">作废状态1为临时作废，－1为彻底作废</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteInStockType(string ID, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteInStockType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认入库类别信息
    /// </summary>
    /// <param>入库类别编号</param>
    /// <param name="AuditStat">确认状态</param>
    /// <param name="Auditor">确认人</param>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatInStockType(string ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetInStockType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加入库类别信息
    /// </summary>
    /// <param>入库类别编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddInStockType(string ID, int iDp_statu, string Name, string Remark, string Oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddInStockType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@statu", SqlDbType.Int);
        com.Parameters["@statu"].Value = iDp_statu;
        com.Parameters.Add("@Ik_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Name"].Value = Name;
        //中间插入各表的数据和参数

        com.Parameters.Add("@Oper", SqlDbType.NVarChar, 60);
        com.Parameters["@Oper"].Value = Oper;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改入库类别信息
    /// </summary>
    /// <param>入库类别编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateInStockType(string ID, string Name, int iDp_statu, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateInStockType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@Ik_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Name"].Value = Name;
        com.Parameters.Add("@statu", SqlDbType.Int);
        com.Parameters["@statu"].Value = iDp_statu;
        //中间插入各表的数据和参数

        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 用于入库类别查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchStockInTypeSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByStockInType", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

}
